package com.base.leetcode;

/**
 * @Author: hdhao
 * @Create: 2023/3/30 - 20:50
 * @Version: v1.0
 */
//查找链表中间节点
public class Leetcode876 {

    //快慢指针法(p1为慢指针,一次走一步,p2为快指针,一次走两步)
    public ListNode middleNode(ListNode head){
        ListNode p1 = head;
        ListNode p2 = head;
        while (p2!=null && p2.next!=null){
            p1 = p1.next;
            p2 = p2.next;
            p2 = p2.next;
        }
        return p1;
    }
}
